namespace DotNetNuke.Services.Exceptions
{
    using DotNetNuke.Entities.Portals;
    using DotNetNuke.Entities.Users;
    using DotNetNuke.Framework.Providers;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Reflection;
    using System.Runtime.Serialization;
    using System.Security.Permissions;
    using System.Web;
    using System.Xml.Serialization;

    [Serializable]
    public class BasePortalException : Exception
    {
        private string m_AbsoluteURL;
        private string m_AbsoluteURLReferrer;
        private int m_ActiveTabID;
        private string m_ActiveTabName;
        private string m_AssemblyVersion;
        private string m_DefaultDataProvider;
        private string m_ExceptionGUID;
        private int m_FileColumnNumber;
        private int m_FileLineNumber;
        private string m_FileName;
        private string m_InnerExceptionString;
        private string m_Message;
        private string m_Method;
        private int m_PortalID;
        private string m_PortalName;
        private string m_Source;
        private string m_StackTrace;
        private int m_UserID;
        private string m_UserName;

        public BasePortalException()
        {
        }

        public BasePortalException(string message) : base(message)
        {
            this.InitilizePrivateVariables();
        }

        protected BasePortalException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            this.InitilizePrivateVariables();
            this.m_AssemblyVersion = info.GetString("m_AssemblyVersion");
            this.m_PortalID = info.GetInt32("m_PortalID");
            this.m_PortalName = info.GetString("m_PortalName");
            this.m_UserID = info.GetInt32("m_UserID");
            this.m_UserName = info.GetString("m_Username");
            this.m_ActiveTabID = info.GetInt32("m_ActiveTabID");
            this.m_ActiveTabName = info.GetString("m_ActiveTabName");
            this.m_AbsoluteURL = info.GetString("m_AbsoluteURL");
            this.m_AbsoluteURLReferrer = info.GetString("m_AbsoluteURLReferrer");
            this.m_ExceptionGUID = info.GetString("m_ExceptionGUID");
            this.m_InnerExceptionString = info.GetString("m_InnerExceptionString");
            this.m_FileName = info.GetString("m_FileName");
            this.m_FileLineNumber = info.GetInt32("m_FileLineNumber");
            this.m_FileColumnNumber = info.GetInt32("m_FileColumnNumber");
            this.m_Method = info.GetString("m_Method");
            this.m_DefaultDataProvider = info.GetString("m_DefaultDataProvider");
            this.m_StackTrace = info.GetString("m_StackTrace");
            this.m_Message = info.GetString("m_Message");
            this.m_Source = info.GetString("m_Source");
        }

        public BasePortalException(string message, Exception inner) : base(message, inner)
        {
            this.InitilizePrivateVariables();
        }

        [SecurityPermission(SecurityAction.Demand, SerializationFormatter=true)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("m_AssemblyVersion", this.m_AssemblyVersion, typeof(string));
            info.AddValue("m_PortalID", this.m_PortalID, typeof(int));
            info.AddValue("m_UserID", this.m_UserID, typeof(int));
            info.AddValue("m_ActiveTabID", this.m_ActiveTabID, typeof(int));
            info.AddValue("m_ActiveTabName", this.m_ActiveTabName, typeof(string));
            info.AddValue("m_AbsoluteURL", this.m_AbsoluteURL, typeof(string));
            info.AddValue("m_ExceptionGUID", this.m_ExceptionGUID, typeof(string));
            info.AddValue("m_AbsoluteURLReferrer", this.m_AbsoluteURLReferrer, typeof(string));
            info.AddValue("m_FileName", this.m_FileName, typeof(string));
            info.AddValue("m_FileLineNumber", this.m_FileLineNumber, typeof(int));
            info.AddValue("m_FileColumnNumber", this.m_FileColumnNumber, typeof(int));
            info.AddValue("m_Method", this.m_Method, typeof(string));
            info.AddValue("m_DefaultDataProvider", this.m_DefaultDataProvider, typeof(string));
            base.GetObjectData(info, context);
        }

        private void InitilizePrivateVariables()
        {
            try
            {
                HttpContext _context = HttpContext.Current;
                PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
                Exception _objInnermostException = new Exception(this.Message, this);
                while (_objInnermostException.InnerException != null)
                {
                    _objInnermostException = _objInnermostException.InnerException;
                }
                ExceptionInfo _exceptionInfo = DotNetNuke.Services.Exceptions.Exceptions.GetExceptionInfo(_objInnermostException);
                try
                {
                    this.m_FileName = _exceptionInfo.FileName;
                }
                catch (Exception exception1)
                {
                    
                    this.m_FileName = "";
                    
                }
                try
                {
                    this.m_FileLineNumber = _exceptionInfo.FileLineNumber;
                }
                catch (Exception exception2)
                {
                    ProjectData.SetProjectError(exception2);
                    this.m_FileLineNumber = -1;
                    
                }
                try
                {
                    this.m_FileColumnNumber = _exceptionInfo.FileColumnNumber;
                }
                catch (Exception exception3)
                {
                    ProjectData.SetProjectError(exception3);
                    this.m_FileColumnNumber = -1;
                    
                }
                try
                {
                    this.m_Method = _exceptionInfo.Method;
                }
                catch (Exception exception4)
                {
                    ProjectData.SetProjectError(exception4);
                    this.m_Method = "";
                    
                }
                try
                {
                    this.m_AbsoluteURLReferrer = _context.Request.UrlReferrer.AbsoluteUri;
                }
                catch (Exception exception5)
                {
                    ProjectData.SetProjectError(exception5);
                    this.m_AbsoluteURLReferrer = "";
                    
                }
                try
                {
                    this.m_AbsoluteURL = _context.Request.Url.AbsolutePath;
                }
                catch (Exception exception6)
                {
                    ProjectData.SetProjectError(exception6);
                    this.m_AbsoluteURL = "";
                    
                }
                try
                {
                    this.m_PortalID = _portalSettings.PortalId;
                    this.m_PortalName = _portalSettings.PortalName;
                }
                catch (Exception exception7)
                {
                    ProjectData.SetProjectError(exception7);
                    this.m_PortalID = -1;
                    this.m_PortalName = "";
                    
                }
                try
                {
                    UserInfo objUserInfo = UserController.GetCurrentUserInfo();
                    this.m_UserID = objUserInfo.UserID;
                }
                catch (Exception exception8)
                {
                    ProjectData.SetProjectError(exception8);
                    this.m_UserID = -1;
                    
                }
                try
                {
                    if (this.m_UserID != -1)
                    {
                        UserInfo objUserInfo = new UserController().GetUser(this.m_PortalID, this.m_UserID);
                        if (objUserInfo != null)
                        {
                            this.m_UserName = objUserInfo.Membership.Username;
                        }
                        else
                        {
                            this.m_UserName = "";
                        }
                    }
                    else
                    {
                        this.m_UserName = "";
                    }
                }
                catch (Exception exception9)
                {
                    ProjectData.SetProjectError(exception9);
                    this.m_UserName = "";
                    
                }
                try
                {
                    this.m_AssemblyVersion = "04.00.00";
                }
                catch (Exception exception10)
                {
                    ProjectData.SetProjectError(exception10);
                    this.m_AssemblyVersion = "-1";
                    
                }
                try
                {
                    this.m_ActiveTabID = _portalSettings.ActiveTab.TabID;
                }
                catch (Exception exception11)
                {
                    ProjectData.SetProjectError(exception11);
                    Exception ex = exception11;
                    this.m_ActiveTabID = -1;
                    
                }
                try
                {
                    this.m_ActiveTabName = _portalSettings.ActiveTab.TabName;
                }
                catch (Exception exception12)
                {
                    ProjectData.SetProjectError(exception12);
                    Exception ex = exception12;
                    this.m_ActiveTabName = "";
                    
                }
                try
                {
                    this.m_ExceptionGUID = Guid.NewGuid().ToString();
                }
                catch (Exception exception13)
                {
                    ProjectData.SetProjectError(exception13);
                    Exception ex = exception13;
                    this.m_ExceptionGUID = "";
                    
                }
                try
                {
                    ProviderConfiguration objProviderConfiguration = ProviderConfiguration.GetProviderConfiguration("data");
                    string strTypeName = ((Provider) objProviderConfiguration.Providers[objProviderConfiguration.DefaultProvider]).Type;
                    this.m_DefaultDataProvider = strTypeName;
                }
                catch (Exception exception14)
                {
                    ProjectData.SetProjectError(exception14);
                    Exception ex = exception14;
                    this.m_DefaultDataProvider = "";
                    
                }
                try
                {
                    this.m_StackTrace = this.StackTrace;
                }
                catch (Exception exception15)
                {
                    ProjectData.SetProjectError(exception15);
                    Exception ex = exception15;
                    this.m_StackTrace = "";
                    
                }
                try
                {
                    this.m_Message = this.Message;
                }
                catch (Exception exception16)
                {
                    ProjectData.SetProjectError(exception16);
                    Exception ex = exception16;
                    this.m_Message = "";
                    
                }
                try
                {
                    this.m_Source = this.Source;
                }
                catch (Exception exception17)
                {
                    ProjectData.SetProjectError(exception17);
                    Exception ex = exception17;
                    this.m_Source = "";
                    
                }
            }
            catch (Exception exception18)
            {
                ProjectData.SetProjectError(exception18);
                Exception exc = exception18;
                this.m_PortalID = -1;
                this.m_UserID = -1;
                this.m_AssemblyVersion = "-1";
                this.m_ActiveTabID = -1;
                this.m_ActiveTabName = "";
                this.m_AbsoluteURL = "";
                this.m_AbsoluteURLReferrer = "";
                this.m_ExceptionGUID = "";
                this.m_FileName = "";
                this.m_FileLineNumber = -1;
                this.m_FileColumnNumber = -1;
                this.m_Method = "";
                this.m_StackTrace = "";
                this.m_Message = "";
                this.m_Source = "";
                
            }
        }

        public string AbsoluteURL
        {
            get
            {
                return this.m_AbsoluteURL;
            }
        }

        public string AbsoluteURLReferrer
        {
            get
            {
                return this.m_AbsoluteURLReferrer;
            }
        }

        public int ActiveTabID
        {
            get
            {
                return this.m_ActiveTabID;
            }
        }

        public string ActiveTabName
        {
            get
            {
                return this.m_ActiveTabName;
            }
        }

        public string AssemblyVersion
        {
            get
            {
                return this.m_AssemblyVersion;
            }
        }

        public string DefaultDataProvider
        {
            get
            {
                return this.m_DefaultDataProvider;
            }
        }

        public string ExceptionGUID
        {
            get
            {
                return this.m_ExceptionGUID;
            }
        }

        public int FileColumnNumber
        {
            get
            {
                return this.m_FileColumnNumber;
            }
        }

        public int FileLineNumber
        {
            get
            {
                return this.m_FileLineNumber;
            }
        }

        public string FileName
        {
            get
            {
                return this.m_FileName;
            }
        }

        public string Method
        {
            get
            {
                return this.m_Method;
            }
        }

        public int PortalID
        {
            get
            {
                return this.m_PortalID;
            }
        }

        public string PortalName
        {
            get
            {
                return this.m_PortalName;
            }
        }

        [XmlIgnore]
        public MethodBase TargetSite
        {
            get
            {
                return base.TargetSite;
            }
        }

        public int UserID
        {
            get
            {
                return this.m_UserID;
            }
        }

        public string UserName
        {
            get
            {
                return this.m_UserName;
            }
        }
    }
}

